home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13175 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  60 lines

  1. Path: cypher.3do.com!user
  2. From: tsw@3do.com (Tom Watson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: can't get system calls to work vis c ver 1
  5. Date: Thu, 04 Apr 1996 13:20:34 -0800
  6. Organization: The 3DO Corporation
  7. Distribution: world
  8. Message-ID: <tsw-0404961320350001@cypher.3do.com>
  9. References: <828623397.22462@snowone.demon.co.uk>
  10. NNTP-Posting-Host: cypher.3do.com
  11.  
  12. In article <828623397.22462@snowone.demon.co.uk>, merv@snowone.demon.co.uk
  13. (snowone) wrote:
  14.  
  15. > Hi
  16. > can anyone help me. I have msvc version one and i'm trying to get
  17. > this program working
  18. > #include <process.h>
  19. > void main()
  20. > {
  21. >    system("dir");
  22. > }
  23. > Will not compile. Says on linking _system is undeclared 
  24. > (note at first would not compile until #undef _WINDOWS)
  25. > have libraries oldnames, libw and mlibcewq
  26. > This is driving me mad as it is such a simple program.
  27.  
  28. 1)  The routine 'system' (as defined in the standard) lives in <stdlib.h>.
  29. 2)  Main is not a 'void' routine.
  30. 3)  As a result of #2, you need to supply a return value.
  31. That would make the program look like:
  32.  
  33. #include <stdlib.h>
  34.  
  35. int main (void)
  36.   {
  37.   return system("dir");
  38.   }
  39.  
  40. The 'void' as argument of main is because you don't use any arguments. 
  41. This assumes that the "command processor" which the routine "system"
  42. invokes (it is system specific) understands the "dir" command.  The
  43. "system" routine returns an 'int' which becomes the return value of 'main'
  44. back to the system, I hope this is acceptable.
  45.  
  46. Now, if this is supposed to work under something like "Windows", and that
  47. environment needs special considerations, you are on your own!!  I don't
  48. do "Windows".
  49.  
  50. -- 
  51. Tom Watson
  52. tsw@3do.com         (Home: tsw@johana.com)
  53.